package com.tyk.bookstore.front.member.controller;


import com.tyk.bookstore.front.common.core.model.result.R;
import com.tyk.bookstore.front.common.other.code.behavior.model.enume.SceneType;
import com.tyk.bookstore.front.member.model.query.MsgCodeCheckQuery;
import com.tyk.bookstore.front.member.model.query.MsgCodeSendWithBehaviorCheckQuery;
import com.tyk.bookstore.front.member.model.query.PwdFindQuery;
import com.tyk.bookstore.front.member.service.MemberService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "会员管理/忘记密码", description = "忘记密码")
@RequestMapping({"api/member/password/find"})
@RestController
@Validated
@RequiredArgsConstructor
public class ForgotPwdController {

    private final MemberService memberService;

    @PostMapping({"code/msg/phone/check-send"})
    @Operation(summary = "发送手机验证码(忘记密码,含行为验证码校验)", description = "发送手机验证码(忘记密码,含行为验证码校验)")
    public R<String> sendMsgCode4ForgotPwdWithBehaviorCheck(
            @Validated @RequestBody MsgCodeSendWithBehaviorCheckQuery query
    ) {
        return R.ok(memberService.sendMsgCodeWithBehaviorCheck(query, SceneType.FIND_PWD));
    }

    @PostMapping({"code/msg/phone/check"})
    @Operation(summary = "校验手机验证码(忘记密码)", description = "校验手机验证码(忘记密码)")
    public R<String> sendMsgCode4ForgotPwd(
            @Validated @RequestBody MsgCodeCheckQuery query
    ) {
        return R.ok(memberService.checkMsgCode(query, SceneType.FIND_PWD));
    }

    @PutMapping
    @Operation(summary = "更新密码", description = "更新密码")
    public R<Object> findPwd(
            @Validated @RequestBody PwdFindQuery query
    ) {
        memberService.findPwd(query, SceneType.REGISTER);
        return R.ok();
    }
}
